package com.xgkj.diyiketang.activity;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xgkj.diyiketang.ProtocolConst;
import com.xgkj.diyiketang.R;

//import butterknife.BindView;
//import butterknife.ButterKnife;
//import butterknife.OnClick;

public class GuoxueSchoolActivity extends BaseActivity implements View.OnClickListener {

    private TextView zhuanyunBack;
    private RelativeLayout guoxueVideoRl;
    private RelativeLayout guoxueMahuaRl;
    private RelativeLayout myGuoxueHyLayout;
    private RelativeLayout myGuoxueCacheRl;
    private RelativeLayout myGuoxueJiluRl;
    private RelativeLayout myGuoxueClectRl;
    private RelativeLayout myGuoxueFriendRl;
    private LinearLayout linearLayout;
    private PopupWindow setPop;
    private TextView ok_btn, title, neirong;
    private PopupWindow qidaiPop;
    private String nickname;
    private PopupWindow mypop;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guoxue_school);
        initUI();
        getPopwindow();
    }

    private void initUI() {
        linearLayout = (LinearLayout) findViewById(R.id.my_guoxue_school);
        zhuanyunBack = (TextView) findViewById(R.id.zhuanyun_back);
        zhuanyunBack.setOnClickListener(this);
        guoxueVideoRl = (RelativeLayout) findViewById(R.id.guoxue_video_rl);
        guoxueVideoRl.setOnClickListener(this);
        guoxueMahuaRl = (RelativeLayout) findViewById(R.id.guoxue_mahua_rl);
        guoxueMahuaRl.setOnClickListener(this);
        myGuoxueHyLayout = (RelativeLayout) findViewById(R.id.my_guoxue_hy_layout);
        myGuoxueHyLayout.setOnClickListener(this);
        myGuoxueCacheRl = (RelativeLayout) findViewById(R.id.my_guoxue_cache_rl);
        myGuoxueCacheRl.setOnClickListener(this);
        myGuoxueJiluRl = (RelativeLayout) findViewById(R.id.my_guoxue_jilu_rl);
        myGuoxueJiluRl.setOnClickListener(this);
        myGuoxueClectRl = (RelativeLayout) findViewById(R.id.my_guoxue_clect_rl);
        myGuoxueClectRl.setOnClickListener(this);
        myGuoxueFriendRl = (RelativeLayout) findViewById(R.id.my_guoxue_friend_rl);
        myGuoxueFriendRl.setOnClickListener(this);
        Intent intent = getIntent();
        if (intent.getStringExtra("nickname") != null) {
            nickname = intent.getStringExtra("nickname");
        }
    }

    private ImageView close_btn;

    private void initDescPopWindow() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.tongzhi_pop, null);
        TextView i_know = (TextView) view.findViewById(R.id.i_know);
        i_know.setOnClickListener(this);
        close_btn = (ImageView) view.findViewById(R.id.close_btn);
        close_btn.setOnClickListener(this);
        setPop = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        setPop.setBackgroundDrawable(new ColorDrawable());
        setPop.setFocusable(true);
        setPop.setOutsideTouchable(true);
    }

    private void getPopwindow() {
        View inflate = LayoutInflater.from(this).inflate(R.layout.item_qidai_pop, null);
        title = (TextView) inflate.findViewById(R.id.title);
        neirong = (TextView) inflate.findViewById(R.id.neirong);
        ok_btn = (TextView) inflate.findViewById(R.id.ok_btn);
        title.setText("期待718");
        neirong.setText("7月18日正式启动");
        ok_btn.setOnClickListener(this);
        WindowManager wm = this.getWindowManager();
        int width = wm.getDefaultDisplay().getWidth();
        int height = wm.getDefaultDisplay().getHeight();
        qidaiPop = new PopupWindow(inflate, width / 2 + 100, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        qidaiPop.setBackgroundDrawable(new ColorDrawable());
        qidaiPop.setTouchable(true);
        qidaiPop.setOutsideTouchable(false);
        qidaiPop.setFocusable(true);
    }

    public void initPop() {
        View inflate = LayoutInflater.from(this).inflate(R.layout.item_qidai_pop, null);
        title = (TextView) inflate.findViewById(R.id.title);
        neirong = (TextView) inflate.findViewById(R.id.neirong);
        ok_btn = (TextView) inflate.findViewById(R.id.ok_btn);
        title.setText("敬请期待");
        neirong.setVisibility(View.GONE);
        ok_btn.setOnClickListener(this);
        WindowManager wm = this.getWindowManager();
        int width = wm.getDefaultDisplay().getWidth();
        int height = wm.getDefaultDisplay().getHeight();
        mypop = new PopupWindow(inflate, width / 2 + 100, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        mypop.setBackgroundDrawable(new ColorDrawable());
        mypop.setTouchable(true);
        mypop.setOutsideTouchable(false);
        mypop.setFocusable(true);

        mypop.showAtLocation(linearLayout, Gravity.CENTER, 0, 0);

    }


    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.zhuanyun_back:
                finish();
                break;
            case R.id.guoxue_mahua_rl:

                initPop();
                break;
            case R.id.guoxue_video_rl:
                Intent intent = new Intent(this, VideoLiveActivity.class);
                intent.putExtra("TYPEID", "0a7a929a76ea44829672fe63733a5b42");
                intent.putExtra(ProtocolConst.MORE_FROM, ProtocolConst.FORM_FIRST);
                intent.putExtra("TITLE", "国学学院");
                startActivity(intent);
                break;
            case R.id.my_guoxue_hy_layout:
                intent = new Intent(this, GuoxueBuyVIPActivity.class);
                intent.putExtra("nickname", nickname);
                startActivity(intent);
                break;
            case R.id.my_guoxue_cache_rl:
//                WindowManager.LayoutParams lp1 = getWindow().getAttributes();
//                lp1.alpha = 0.5f; //0.0-1.0
//                getWindow().setAttributes(lp1);
//                ColorDrawable dw1 = new ColorDrawable(0x60000000);
//                qidaiPop.setBackgroundDrawable(dw1);
                qidaiPop.showAtLocation(linearLayout, Gravity.CENTER, 0, 0);
//                setPop.showAtLocation(linearLayout, Gravity.CENTER,0,0);
                break;
            case R.id.my_guoxue_jilu_rl:
//                WindowManager.LayoutParams lp2 = getWindow().getAttributes();
//                lp2.alpha = 0.5f; //0.0-1.0
//                getWindow().setAttributes(lp2);
//                ColorDrawable dw2 = new ColorDrawable(0x60000000);
//                qidaiPop.setBackgroundDrawable(dw2);
                qidaiPop.showAtLocation(linearLayout, Gravity.CENTER, 0, 0);
//                setPop.showAtLocation(linearLayout, Gravity.CENTER,0,0);
                break;
            case R.id.my_guoxue_clect_rl:
//                WindowManager.LayoutParams lp3 = getWindow().getAttributes();
//                lp3.alpha = 0.5f; //0.0-1.0
//                getWindow().setAttributes(lp3);
//                ColorDrawable dw3 = new ColorDrawable(0x60000000);
//                qidaiPop.setBackgroundDrawable(dw3);
                qidaiPop.showAtLocation(linearLayout, Gravity.CENTER, 0, 0);
//                setPop.showAtLocation(linearLayout, Gravity.CENTER,0,0);
                break;
            case R.id.my_guoxue_friend_rl:
                Intent intent_yaoqing = new Intent(mContext, ZhuanyunOrderActivity.class);
                intent_yaoqing.putExtra("type", "yaoqing");
                startActivity(intent_yaoqing);
                break;
            case R.id.ok_btn:
                if (qidaiPop != null && qidaiPop.isShowing())
                    qidaiPop.dismiss();
                if (mypop != null && mypop.isShowing())
                    mypop.dismiss();
                break;

        }
    }
}
